package com.ecloud.gardensterminal.controller.dto;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

/**
 * @author Squbi
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GardensDeviceSelectDto {
    private Integer deviceId;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime startTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime endTime;
    private Integer pageIndex;
    private Integer pageSize;

    public GardensDeviceSelectDto(Integer deviceId, Integer pageSize, Integer pageIndex) {
        this.pageIndex = pageIndex;
        this.pageSize = pageSize;
        this.deviceId = deviceId;
    }

    public GardensDeviceSelectDto(String json) {
        GardensDeviceSelectDto dto = JSON.parseObject(json, this.getClass());
        this.pageIndex = dto.getPageIndex();
        this.pageSize = dto.getPageSize();
        this.deviceId = dto.getDeviceId();
        this.startTime = dto.getStartTime();
        this.endTime = dto.getEndTime();
    }
}
